//
//  YSProdReviewItemFrame.m
//  Yueshi
//
//  Created by Northwan on 15/10/11.
//  Copyright © 2015年 悦食中国. All rights reserved.
//

#import "YSProdReviewItemFrame.h"
#import "YSSellerReplyView.h"


@implementation YSProdReviewItemFrame

-(void)setComment:(YSProdComment *)comment{
    _comment = comment;
    
    //avatar
    _avatarFrame = CGRectMake(YSPublicXInset, YSPublicXInset, 72/2, 72/2);
    
    //name
    CGSize nameSize = [comment.userName sizeWithFont:SYS_FONT(nameFont)];
    _nameFrame = CGRectMake(CGRectGetMaxX(_avatarFrame)+YSPublicXInset, CGRectGetMinY(_avatarFrame), nameSize.width, nameSize.height);
    
    //好评度
    NSString *levelTipString = @"好评度";
    CGSize levelTipSize = [levelTipString sizeWithFont:SYS_FONT(levelFont)];
    _leveltTipFrame = CGRectMake(CGRectGetMaxX(_avatarFrame)+YSPublicXInset, CGRectGetMaxY(_avatarFrame)-levelFont, levelTipSize.width, levelFont);
    
    //levelView
    _levelFrameX = CGRectGetMaxX(_leveltTipFrame)+YSPublicXInset;
    UIImage *img =  [UIImage imageNamed:@"btn_star_gray"];
    _levelFrameY = CGRectGetMaxY(_avatarFrame)-img.size.height;
    
    //time
    CGSize timeSize = [comment.createTime sizeWithFont:SYS_FONT(timeFont)];
    _timeFrame = CGRectMake(SCREENW-timeSize.width-YSPublicXInset, CGRectGetMaxY(_avatarFrame)-_avatarFrame.size.height/2, timeSize.width, timeSize.height);
    
    //content
    CGSize contentSize = [_comment.comment sizeWithFont:SYS_FONT(timeFont) constrainedToSize:CGSizeMake(SCREENW-YSPublicXInset*2, MAXFLOAT)];
    _contentFrame = CGRectMake(YSPublicXInset, CGRectGetMaxY(_avatarFrame)+YSPublicXInset, contentSize.width, contentSize.height);

    _spliteFrame = CGRectMake(0, CGRectGetMaxY(_contentFrame)+YSPublicXInset, SCREENW, YSPublicXInset);
    
    //photoView
    if(_comment.commentImage.count){
        _photosFrameX  = 0;
        _photosFrameY = CGRectGetMaxY(_contentFrame)+YSPublicXInset;
        
//        _spliteFrame = CGRectMake(0, CGRectGetMaxY(_contentFrame)+YSPublicXInset*2+(SCREENW-YSPublicXInset*5)/4, SCREENW, YSPublicXInset);
        _spliteFrame.origin.y = CGRectGetMaxY(_contentFrame)+YSPublicXInset*2+(SCREENW-YSPublicXInset*5)/4;
    }
    
    // seller reply content
    if (_comment.reComment) {
        CGFloat y = _photosFrameY ? CGRectGetMaxY(_contentFrame) + (SCREENW-YSPublicXInset*5)/4 + YSPublicXInset + 15 : CGRectGetMaxY(_contentFrame) + 15;
        _sellerReplyFrame = CGRectMake(0, y, SCREENW, [YSSellerReplyView getHeightWithContent:_comment.reComment]);
        _spliteFrame.origin.y = CGRectGetMaxY(_sellerReplyFrame)+YSPublicXInset;
    }
    
     _cellHeight = CGRectGetMaxY(_spliteFrame);
    //self
    _frame = CGRectMake(0, 0, SCREENW, _cellHeight);
}

@end
